home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15123 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  72 lines

  1. Newsgroups: comp.infosystems.www.servers.unix,comp.lang.c
  2. Path: news.draper.com!nntp
  3. From: Brandon Shalton <bshalton@draper.com>
  4. Subject: Opening a binary file.... (dealing with content-type & WWW)
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <317351DE.E7E@draper.com>
  7. Sender: nntp@draper.com (NNTP Master)
  8. Nntp-Posting-Host: bam3106cx.draper.com
  9. Content-Transfer-Encoding: 7bit
  10. Organization: Draper Laboratory
  11. Mime-Version: 1.0
  12. Date: Tue, 16 Apr 1996 07:53:02 GMT
  13. X-Mailer: Mozilla 2.0 (Macintosh; I; 68K)
  14.  
  15. Hello, 
  16.  
  17. I am trying to establish content-types (mime) based upon the header 
  18. of the file, rather than relying on the file extension.  I have 
  19. instances where file extensions overlap...ex. .doc (microsoft word), 
  20. .doc (ascii text document).
  21.  
  22. To be able to set the content-type correctly to launch the 
  23. appropriate viewer, I am modifying the "file" command to be able to 
  24. look up by magic types.  I have coded the magic type  
  25. application/msword in the magic file.  The modified file program 
  26. would then open the desired file, and stream it out to the user.
  27.  
  28. Originally I was doing a fork/exec and basically cat'ting the file.  
  29. This works under Solaris, but for some reason, it doesn't work on 
  30. SunOS.  Plus, I have seen hung processes.  
  31.  
  32. I have decided to take out the fork/exec and replace it with a 
  33. simple open file, read contents, send to browser routine.
  34.  
  35. This is my first cut...
  36.  
  37.  
  38.  
  39.                 fd2=open(entries[0].val,O_RDONLY);
  40.                 for(;;)
  41.                         {
  42.                 if(     read(fd2, tbuf, 1) <=0 ) exit(1);
  43.                         printf("%s", tbuf);
  44.                         }
  45.  
  46.  
  47. This snippet does read the file, and sends the file out..but when 
  48. viewed from Microsoft Word, the file comes through as text, showing 
  49. the control characters at the header of the file.  It looks like 
  50. ascii is being sent out rather than binary.
  51.  
  52. I have also tried:
  53.  
  54.  
  55.  
  56.                                                                 fin2=fopen(entries[0].val,"rb");
  57.                 while( ch=fgetc(fin2) != EOF )
  58.                         printf("%c", ch);
  59.                 exit(1);
  60.  
  61. and have gotten the same type of result.
  62.  
  63. Any pointers would be greatly appreciated...
  64.  
  65. -Brandon
  66.  
  67. ** Web Developer
  68. ** Draper Laborator
  69. ** Cambridge, MA USA
  70. **
  71. ** bshalton@draper.com
  72.